package com.huanghuai.retail.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huanghuai.retail.common.R;
import com.huanghuai.retail.dto.AddPORepositoryDto;
import com.huanghuai.retail.entity.*;
import com.huanghuai.retail.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zjh
 * @since 2023-05-04
 */
@Api("新增出入库单")
@Slf4j
@RestController
@RequestMapping("/pORepository")
public class PORepositoryController {

    @Autowired
    private IPORepositoryService repositoryService;

    @ApiOperation("新增出入库单")
    @PostMapping
    public R<String> InOutBound(@RequestBody @Validated AddPORepositoryDto poRepositoryDto) {

        if (poRepositoryDto==null){
            return R.error("新增失败");
        }
        Boolean is = repositoryService.savePORepositoryAndGoods(poRepositoryDto);
        if (is)
            return R.success( "新增成功");
        else return R.error("新增失败");
    }
    @GetMapping
    public Object get() {
        List<PORepository> list = repositoryService.list();
        return list;
    }
    /**
     * @author Lu Zixiang
     * @date 2023/5/9 16:17
     * @param
     * @return com.huanghuai.retail.common.R<com.baomidou.mybatisplus.extension.plugins.pagination.Page>
     */
    @ApiOperation("查询出入库单")
    @GetMapping("/page")
    public R<Page> findByPage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false) String []typeName,
            @RequestParam(required = false) Integer []storageId,
            @RequestParam(required = false) String []billNum,
            @RequestParam(required = false) Long []goodsId,
            @RequestParam(required = false) Long []typeId,
            @RequestParam(required = false) String []shopName
    ){
        return repositoryService.getPoGoodsDtoPage(page, pageSize, startTime, endTime, typeName, storageId,
                billNum, goodsId, typeId, shopName);
    }

    @GetMapping("/findAllType")
    public R<List<Map<String, String>>> getAllType(){
        return R.success(BillTypeEnum.getAllType());
    }

    @GetMapping("/findAllBillNumber")
    public R<List<PORepository>> getAllTBillNumber(){
        return repositoryService.findAllBillNumber();
    }
    
    
    @GetMapping("/collect")
    public R<Map> collectPORepository(
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false) String []typeName,
            @RequestParam(required = false) Integer []storageId,
            @RequestParam(required = false) String []billNum,
            @RequestParam(required = false) Long []goodsId,
            @RequestParam(required = false) Long []typeId,
            @RequestParam(required = false) String []shopName
    ){
        return repositoryService.collectPORepository(startTime, endTime, typeName, storageId,
                billNum, goodsId, typeId, shopName);
    }
    
}
